package ulht.ia;
import Interface.*;

import java.util.Random;

public class mainAntigo {
	private static Random aleatorio = new Random();
	
	private static String horario[][][] = {{{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""}},
			{{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""}},
			{{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""}},
			{{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""}},
			{{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""},{"","","","",""}},};
	private static String disciplinas[] = {"001", "002", "003", "004", "005", "006", "007"};
	private static String turmas[] = {"01", "02", "03", "04", "05", "06"};
	
	private static String stack[] = {"","","","","","","","","","","","","","",
					  "","","","","","","","","","","","","","",
					  "","","","","","","","","","","","","","",
					  "","","","","","","","","","","","","","",
					  "","","","","","","","","","","","","","",
					  "","","","","","","","","","","","","",""};
	
	public static boolean checkTurmaDisponivel(int dia, int slot, String turma){
		for (int s=0; s<5; s++){
			if (horario[s][slot][dia].endsWith(turma))
				return false;
		}
		return true;
	}
	
	
	public static void mainAntigo(String[] args) {
		
		String linha = "";
		int tLinha = 0;
		
		//constroi stack
		int st = 0;
			for(int d=0; d<disciplinas.length; d++){
				for (int t=0; t < turmas.length; t++){
					stack[st++] = disciplinas[d] + turmas[t];
					stack[st++] = disciplinas[d] + turmas[t];
				}
			}
		
		/*
		for (st=0; st<stack.length;st++)
			System.out.println(stack[st]);	
		*/	
		
		//inicializar
		for (int s=0; s<stack.length;s++){
			int sala = 0, dia = 0, slot = 0;
			sala = aleatorio.nextInt(5);
			dia = aleatorio.nextInt(5);
			slot = aleatorio.nextInt(8);
			//escolher a sala aleatoriamente
			while((!horario[sala][slot][dia].isEmpty()) || (!checkTurmaDisponivel(dia, slot, stack[s].substring(stack[s].length()-2, stack[s].length())))){
				sala = aleatorio.nextInt(5);
				dia = aleatorio.nextInt(5);
				slot = aleatorio.nextInt(8);
			}
			horario[sala][slot][dia] = stack[s];
			
			//System.out.println("sala: " + sala + ", dia: " + dia + ", slot: " + slot);
		}
		/*
		for (int l=0; l<=7; l++){
			for (int c=0; c<=4; c++){
				horario[l][c] = "S000000";
			}
		}
		*/
		//carregar salas vazias
		for (int s=0; s<5; s++){
			for (int l=0; l<=7; l++){
				for (int c=0; c<=4; c++){
					if (horario[s][l][c].isEmpty())
						horario[s][l][c] = "     ";
				}
			}
		}
		
		//mostrar para salas
		for (int s=0; s<5; s++){
			System.out.println("\nSALA " + (s+1) + "    2�    3�    4�    5�    6�");
			for (int l=0; l<=7; l++){
				System.out.printf("slot %d: ", l+1);
				for (int c=0; c<=4; c++){
						System.out.print(horario[s][l][c] + " ");
				}
				System.out.println();
			}
		}
		
		//mostrar para turmas
		for (int t = 0; t < 6; t++)
		{
			System.out.println("\nTURMA " + (t+1) + "   2�    3�      4�     5�     6�");
			for (int l=0; l<=7; l++){
				for (int c=0; c<=4; c++){
					tLinha = linha.length();
					for (int s=0; s<5; s++){
						if (horario[s][l][c].endsWith("0"+(t+1)))
							linha += horario[s][l][c].substring(0, horario[s][l][c].length()-2) + "(" + (s+1) + ") ";
					}
					if (!(linha.length() > tLinha))
						linha += "       ";
				}
				System.out.printf("slot %d: %s\n", l+1, linha);
				linha = "";
			}
		}
		
		//mostrar genoma
		
			for (int l=0; l<=7; l++){
				System.out.printf("slot %d: ", l+1);
				for (int c=0; c<=4; c++){
					for (int s=0; s<5; s++)
						System.out.print(horario[s][l][c]);
				}
				System.out.println();
			}
		
                        
                        
                        
                        
	}

}
